<?php

include ("Edge.php");
include ("Pattern.php");

class Node {
	var 	$id;
	var 	$pattern;
	var 	$error;
	var		$edges;
	
	public function __construct (Pattern $pttrn, $i){
		$this->edges = array ();
		$this->pattern = $pttrn;
		$this->id = $i;
		$this->error = 0.0;
	}
	
	public function half_to(array $__pattern){
		return  $this->pattern->half_to($__pattern);
	}
	
	public function add_edge ($end_id, $edge_val){
		$edge = new Edge($end_id, $edge_val);
		$this->edges[] = $edge;
	}
	
	public function erase_edge($n2){
		for ($i = 0; $i < count($this->edges); $i++){
			if ($this->edges[$i]->node_id == $n2){
				unset($this->edges[$i]); 
        $this->edges = array_values($this->edges);
				break;
			}
		}		
	}
		
	public function remove_edges($limit){
		for ($i = 0; $i < count($this->edges); $i++){
			if ($this->edges[$i]->weight >= $limit){
				unset($this->edges[$i]); 
        $this->edges = array_values($this->edges);
			}
		}		
	}
	
	public function increase_local_error ($inc) {
		$this->error += $inc;
	}
	
	public function move_to (array $pattern, $eb){
		 $this->pattern->move_to($pattern, $eb);
	}
	
	public function printing (){
		echo "N: " . $this->id . "E:" . $this->error . '->';
		for ($i = 0; $i < count($this->edges); $i++){
			$this->edges[$i]->printing();
		}
		echo '</br>';
	}
}
?>